package mysql

import "gorm.io/gorm"

type UserInfo struct {
	gorm.Model
	PhoneNum      string `gorm:"type:varchar(30);not null;comment:'必填'"`
	Pwd           string `gorm:"type:char(32);not null;comment:'必填'"`
	NickName      string `gorm:"type:varchar(30);not null,comment:'必填'"`
	AvatarLink    string `gorm:"type:varchar(500);"`
	AccountStatus int    `gorm:"type:int(11);default:0;not null"`
	FollowNum     int    `gorm:"type:int(11);not null"`
	FansNum       int    `gorm:"type:int(11);not null"`
	UserLevel     string `gorm:"type:varchar(30);not null"`
}

func (i *UserInfo) UserFindByPhoneNum(db *gorm.DB, phonenum string) error {
	return db.Debug().Where("phone_num=?", phonenum).FirstOrCreate(i).Error
}

func (i *UserInfo) UpdatePwd(db *gorm.DB) error {
	return db.Debug().Updates(i).Error
}

func (i *UserInfo) UserFindByPhone(db *gorm.DB, phone string) error {
	return db.Debug().Where("phone_num=?", phone).First(i).Error
}

func (i *UserInfo) UpdateUserName(db *gorm.DB) error {
	return db.Debug().Updates(i).Error
}

func (i *UserInfo) UserFindById(db *gorm.DB, id int64) error {
	return db.Debug().Where("user_infos.id=?", id).First(i).Error
}
